package cn.okcmd.log_jul;

import sun.reflect.Reflection;

import java.io.IOException;
import java.util.Date;
import java.util.logging.*;

/**
 * create by caoqg on 2021/7/15
 * 功能说明:
 */
public class MyJUL {
    public static void main(String[] args) throws IOException {
        String str = String.format("%1$tY/%1$tm/%1$td %1$tH:%1$tM:%1$tS", new Date());
        System.out.println(str);
        System.setProperty("java.util.logging.SimpleFormatter.format", "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %1$Tp %2$s %4$s: %5$s%6$s%n");
        Logger logger = Logger.getLogger(MyJUL.class.getName());
        logger.setLevel(Level.ALL);
        Handler handler = new FileHandler("./logs/myjul_log%u.log");
        ConsoleHandler ch = new ConsoleHandler();
        handler.setFormatter(new SimpleFormatter());
        ch.setFormatter(new SimpleFormatter());
        handler.setLevel(Level.ALL);
        logger.setUseParentHandlers(false);
        logger.addHandler(handler);
        logger.addHandler(ch);
        logger.severe("this is severe");
        logger.warning("this is warn");
        logger.info("this is test");
        logger.config("this is config");
        logger.fine("this is fine");
        logger.finer("this is finer");
        logger.finest("this is finest");
        LogRecord lr = new LogRecord(Level.INFO,"this is {0} this is {1} this {2}-{1}");
        lr.setParameters(new Object[]{1, 2, 3, 4});
        lr.setThrown(new Throwable("这里有个错误"));
        logger.log(lr);
    }
}
